﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Sharp.Interprocess.MemoryManager
{
    internal static class AllocatorUtil
    {
        internal static int FindClosestSegmentSize(int allocationSize)
        {
            var closestSegmentSize = Convert.ToInt32(Math.Pow(2, Math.Ceiling(Math.Log(allocationSize, 2))));
            return closestSegmentSize;
        }

        internal static void WaitOneWithException(this Mutex mutex,int mutexTimeout)
        {
            if (!mutex.WaitOne(mutexTimeout))
            {
                throw new TimeoutException("Mutex timed-out while trying to acquire lock. Maybe a dead-lock?");
            }
        }
    }
}
